package com.yyfax.ph.personal.authority.forgot;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;

import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

public class ForgotPwdModel extends Model {
	private static final String TAG = ForgotPwdModel.class.getSimpleName();

	@Override
	public Observable getObservable(Object params, int requestCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.forgetPwd(token, (ForgotPwdParams) params);
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		RetrievePwdResult retrievePwdResult = cast(obj);
		EventAgent.post(retrievePwdResult);
	}

	private interface Service {
		@POST("sys/user/forgetPwd")
		Observable<RetrievePwdResult> forgetPwd(@Header("token") String token, @Body ForgotPwdParams params);
	}

	public static class ForgotPwdParams {
		String loginName;// 手机号
		String password; // 新密码
		String verifyId; // 校验订单号
		String retId; // 极光Id
	}

	static class RetrievePwdResult extends BaseResultEntity<String> {
	}

}
